trigger HandleProductPriceChange on Merchandise__c (after update) {
	// update invoice line items associated with open invoices
	List<LineItem__c> openLineItems =
	 [SELECT j.UnitPrice__c, j.Merchandise__r.Price__c
	  FROM LineItem__c j
	  WHERE j.InvoiceStatement__r.Status__c = '交渉中'
	  AND j.Merchandise__r.id IN :Trigger.new
	   FOR UPDATE ];
	   
   	for (LineItem__c li: openLineItems){
   		if ( li.Merchandise__r.Price__c < li.UnitPrice__c) {
   			li.UnitPrice__c = li.Merchandise__r.Price__c;
   		}
   	}
   	
   	update openLineItems;
}